<template>
  <div class="home">
    <!-- 顶部横幅 -->
    <div class="banner" :style="{ backgroundImage: `url(${require('@/assets/home/background.png')})`, backgroundSize: 'cover', backgroundPosition: 'center' }">
      <div class="banner-content">
        <h1>SHARED-AI</h1>
        <p>让每个人都能使用AI</p>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 最新发布 -->
      <section class="section">
        <h2 class="section-title">最新发布</h2>
        <div class="tools-grid">
          <AIToolCard
            v-for="tool in latestAITools"
            :key="tool.id"
            :id="tool.id"
            :title="tool.title"
            :description="tool.description"
            :thumbnail="tool.thumbnail"
            :sales="tool.sales"
            :last-purchase-time="tool.lastPurchaseTime"
          />
        </div>
      </section>
      
      <!-- 美观的分割线 -->
      <div class="section-divider">
        <div class="divider-line"></div>
        <div class="divider-icon">
          <i class="el-icon-star-on"></i>
        </div>
        <div class="divider-line"></div>
      </div>
      
      <!-- 稳定运行 -->
      <section class="section stable-section">
        <h2 class="section-title">稳定运行</h2>
        <div class="section-subtitle">这些AI工具已经稳定运行超过3个月，用户好评如潮</div>
        <div class="tools-grid">
          <AIToolCard
            v-for="tool in stableAITools"
            :key="tool.id"
            :id="tool.id"
            :title="tool.title"
            :description="tool.description"
            :thumbnail="tool.thumbnail"
            :sales="tool.sales"
            :last-purchase-time="tool.lastPurchaseTime"
            :stable="true"
          />
        </div>
      </section>
    </div>
  </div>
</template>

<script>
import AIToolCard from '@/components/AIToolCard.vue'

import { getLatestAITools, getStableAITools } from '@/api/home'

export default {
  name: 'HomeView',
  components: {
    AIToolCard
  },
  data() {
    return {
      latestAITools: [],
      stableAITools: []
    }
  },
  created() {
    this.getLatestAITools()
    this.getStableAITools()
  },
  methods: {
    getLatestAITools() {
      getLatestAITools().then(response => {
        this.latestAITools = response.data

        this.latestAITools.forEach(tool => {
          tool.thumbnail = require(`@/assets/home/${tool.thumbnail}-logo.png`)
        })
      })
    },
    getStableAITools() {
      getStableAITools().then(response => {
        this.stableAITools = response.data

        this.stableAITools.forEach(tool => {
          tool.thumbnail = require(`@/assets/home/${tool.thumbnail}-logo.png`)
        })
      })
    }
  }
}
</script>

<style scoped>
/* 整体容器样式 */
.home {
  background-color: #ffffff;
  color: #333333;
  min-height: 100vh;
}

/* 顶部横幅样式 */
.banner {
  height: 60vh;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* 横幅内容样式 */
.banner-content h1 {
  font-size: 4rem;
  margin-bottom: 1rem;
  color: #ffffff;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.banner-content p {
  font-size: 1.5rem;
  color: #ffffff;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* 主要内容区域样式 */
.main-content {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* 区块样式 */
.section {
  margin-bottom: 3rem;
}

/* 区块标题样式 */
.section-title {
  font-size: 2rem;
  color: #333333;
  margin-bottom: 1rem;
  text-align: center;
}

/* 区块副标题样式 */
.section-subtitle {
  font-size: 1rem;
  color: #666666;
  margin-bottom: 2rem;
  text-align: center;
}

/* 稳定运行区块样式 */
.stable-section {
  background-color: white;
  padding: 2rem;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
}

.stable-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
}

/* AI工具卡片网格布局 */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 2rem;
  justify-items: center;
}

/* 分割线样式 */
.section-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 3rem 0 0rem;
  padding: 0 1rem;
}

.divider-line {
  flex-grow: 1;
  height: 1px;
  background: linear-gradient(to right, rgba(63, 93, 98, 0.05), rgba(63, 93, 98, 0.3), rgba(63, 93, 98, 0.05));
}

.divider-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 10px rgba(63, 93, 98, 0.15);
  margin: 0 1.5rem;
  position: relative;
  z-index: 1;
  transition: all 0.3s ease;
}

.divider-icon i {
  color: #3F5D62;
  font-size: 1.5rem;
}

.divider-icon:hover {
  transform: rotate(180deg);
  box-shadow: 0 4px 15px rgba(63, 93, 98, 0.25);
}

/* 响应式布局调整 */
@media (max-width: 768px) {
  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
  }
  
  .stable-section {
    padding: 1.5rem;
  }
  
  .section-divider {
    margin: 1.5rem 0 2.5rem;
  }
  
  .divider-icon {
    width: 40px;
    height: 40px;
    margin: 0 1rem;
  }
  
  .divider-icon i {
    font-size: 1.2rem;
  }
}
</style> 